package com.applet.code.util;

import java.util.UUID;
import java.util.regex.Pattern;

public class StringUtils {

	private StringUtils() {}

	/**
	 * 追加 append('12',"34",5,67.78)
	 * @param strs
	 * @return
	 */
	public static String append(Object... strs) {
		StringBuilder _sbuilder = new StringBuilder();
		for (Object _str : strs) {
			_sbuilder.append(String.valueOf(_str));
		}
		return _sbuilder.toString();
	}

	public static boolean isEmpty(String str){
		return str == null ? true : "".equals(str.trim());
	}
	
	/**
	 * 先前补齐至bitNumber位
	 * @param str 原始
	 * @param bitNumber 
	 * @param filler填充字符
	 * @return
	 */
	public static String lpad(Object str, int bitNumber,char filler){
		StringBuilder sb = new StringBuilder(str.toString());
		for (int i = str.toString().length(); i < bitNumber; i++) {
			sb.insert(0, filler);
		}
		return sb.toString();
	}
	/**
	 * 先后补齐至bitNumber位
	 * @param str 原始
	 * @param bitNumber 
	 * @param filler填充字符
	 * @return
	 */
	public static String rpad(Object str, int bitNumber,char filler){
		StringBuilder sb = new StringBuilder(str.toString());
		for (int i = str.toString().length(); i < bitNumber; i++) {
			sb.append(filler);
		}
		return sb.toString();
	}
	
	/**
	 * 获取uuid
	 * 
	 * @return
	 */
	public static String getUUID() {

		return UUID.randomUUID().toString().replace("-", "");
	}

	public static boolean equals(String s, String k) {
		return s == null || k == null ? false : s.equals(k);
	}

	public static boolean equalsIgnoreCase(String s, String k) {
		return s == null || k == null ? false : s.equalsIgnoreCase(k);
	}

	/**
	 * 默认值
	 * @param str
	 * @param _defualt 缺省情况下值
	 * @return
	 */
	public static String _default(String str, String _defualt) {
		return str == null ? _defualt : str;
	}
	
	/**
	 * 正则校验
	 * @param regex
	 * @param data
	 * @return
	 */
	public static boolean regex(String regex, Object data){
		return Pattern.compile(regex).matcher(data.toString()).matches();
	}
	
}
